/*    */ package com.qmsk.business.store.outstockbill.service;
/*    */ 
/*    */ import com.qmsk.business.store.goodsStock.dao.GoodsStockDao;
/*    */ import com.qmsk.business.store.outstockbill.dao.OutStockBillDAO;
/*    */ import com.qmsk.business.store.outstockdtl.dao.OutStockDtlDAO;
/*    */ import com.utils.basic.ObjectComm;
/*    */ import com.utils.gson.in.GsonHeadManyRows;
/*    */ import com.utils.gson.in.GsonHeadOneRow;
/*    */ import com.utils.web.ResponseUtils;
/*    */ import java.sql.SQLException;
/*    */ import javax.servlet.http.HttpServletResponse;
/*    */ import org.springframework.beans.factory.annotation.Autowired;
/*    */ 
/*    */ public class OutStockBillService
/*    */ {
/*    */ 
/*    */   @Autowired
/*    */   private OutStockBillDAO dao;
/*    */ 
/*    */   @Autowired
/*    */   private OutStockDtlDAO dtlDao;
/*    */ 
/*    */   @Autowired
/*    */   private GoodsStockDao goodsStockDao;
/*    */ 
/*    */   public Integer insertOutBill(GsonHeadOneRow g, GsonHeadManyRows m)
/*    */     throws SQLException
/*    */   {
/* 29 */     Integer nResult = null;
/* 30 */     nResult = Integer.valueOf(this.dao.insertGsonHeadOneRow(g));
/* 31 */     if (nResult.intValue() > 0) {
/* 32 */       Long id = this.dao.getLastId();
/* 33 */       if (m.isExistsData()) {
/* 34 */         m.autoAddHeadData("id", id);
/* 35 */         m.setHeadValueOfObject("id", id);
/* 36 */         nResult = Integer.valueOf(this.dtlDao.insertGsonHeadManyRows(m));
/*    */       }
/*    */     }
/* 39 */     return nResult;
/*    */   }
/*    */ 
/*    */   public Integer check(Long id, HttpServletResponse response) throws SQLException
/*    */   {
/* 44 */     Integer nResult = null;
/* 45 */     nResult = this.dao.updateStatusOfId(id);
/* 46 */     if (nResult.intValue() > 0) {
/* 47 */       GsonHeadManyRows g = this.dtlDao.getManyRowsOfId(id);
/* 48 */       if ((g != null) && (g.isExistsData())) {
/* 49 */         for (int k = 0; k < g.getDataLength(); ++k) {
/* 50 */           Long goodsId = ObjectComm.objectToLong(g.getValueOfName(
/* 51 */             "goodsId", k));
/* 52 */           Long houseId = ObjectComm.objectToLong(g.getValueOfName(
/* 53 */             "houseId", k));
/* 54 */           Double sum = this.goodsStockDao.getNumOfGoodsIdAndHouseId(
/* 55 */             houseId, goodsId);
/* 56 */           Double num = ObjectComm.objectToDouble(
/* 57 */             g.getValueOfName("nums", k), Integer.valueOf(0));
/* 58 */           if (sum.doubleValue() >= num.doubleValue()) {
/* 59 */             num = Double.valueOf(sum.doubleValue() - num.doubleValue());
/*    */ 
/* 62 */             nResult = Integer.valueOf(this.goodsStockDao.updateCountOfGoodsIdAndHouseId(
/* 63 */               num, houseId, goodsId));
/*    */           }
/*    */           else {
/* 66 */             nResult = Integer.valueOf(0);
/* 67 */             ResponseUtils.setErrorMsgResponse("库存不足", response);
/* 68 */             break;
/*    */           }
/*    */         }
/*    */       }
/*    */     }
/* 73 */     return nResult;
/*    */   }
/*    */ 
/*    */   public String getOutNo(Long shopId) throws SQLException {
/* 77 */     return this.dao.getMaxBillNo(shopId);
/*    */   }
/*    */ 
/*    */   public Long getLastId() throws SQLException {
/* 81 */     return this.dao.getLastId();
/*    */   }
/*    */ }

/* Location:           C:\Users\Administrator\Desktop\新建文件夹\WEB-INF\classes\
 * Qualified Name:     com.qmsk.business.store.outstockbill.service.OutStockBillService
 * JD-Core Version:    0.5.3
 */